package com.medicine.controller;

import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pagination.Page;
import po.Equipment;
import po.Ypkcxx;
import requestvo.EquipOfLabReqVo;
import requestvo.EquipmentReqVo;
import requestvo.LabReqVo;
import requestvo.SupplierReqVo;
@Controller
public class EquipmentOfLabController extends BaseController{
	@RequestMapping("/sbfcxx")
	public void findYpxx(EquipOfLabReqVo equipOfLabReqVo,HttpServletResponse response) throws IOException{
		Page<EquipOfLabReqVo> page=equipmentOfLabService.findsbfcxx(equipOfLabReqVo);
		JSONObject jsonObject=new JSONObject();
		jsonObject.element("rows", page.getResults());
		jsonObject.element("total", page.getTotalRecord());
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8");  
		response.getWriter().print(jsonObject.toString());
	}
	/*@RequestMapping("/updatesbfcxx")
	public void updateYpkcxx(EquipOfLabReqVo equipOfLabReqVo,HttpServletResponse response) throws IOException{
		ypkcxxService.updateYpkcxx(ypkcxx);
		response.sendRedirect("sb_of_lab.html");
	}*/
	@RequestMapping("/addsbfcxx")
	public String addsbfcxx(EquipOfLabReqVo equipOfLabReqVo,HttpServletResponse response,HttpServletRequest request) throws IOException{
		LabReqVo labReqVo=null;
		EquipmentReqVo equipmentReqVo = null;
		/*1.插入前，校验是否有这个lab_name，在t_lab表查*/
		labReqVo.setSys_name(equipOfLabReqVo.getSys_name());
		labReqVo=labService.getLabName(equipOfLabReqVo.getSys_name());
		if(labReqVo.getSys_no()==null||labReqVo.getSys_no().equals("")){
			return "500.jsp";
		}
		/*2.检查是否有该sb_no,在t_equipment表查*/
		equipmentReqVo=sbkcxxService.getEquipmentName(equipOfLabReqVo.getSb_name());
		if(equipmentReqVo.getSb_no()==null||equipmentReqVo.getSb_no().equals("")){
			return "500.jsp";
		}
		/*3.检查现在是否存在这个关系*/
		
		equipmentReqVo.setSb_name(equipOfLabReqVo.getSb_name());	
		
		equipmentOfLabService.addsbfcxx(equipOfLabReqVo);
		request.setAttribute("ypkcxx", equipOfLabReqVo);
		return "addypkcxxsucc.jsp";
	}/*
	@RequestMapping("/delsbfcxx")
	public void delYpkcxx(String ids,HttpServletResponse response) throws IOException{
		String[] id=ids.split(",");
		Integer[] integers=new Integer[id.length];
		for(int i=0;i<id.length;++i)
			integers[i]=Integer.parseInt(id[i]);
		ypkcxxService.delYpkcxx(integers);
		response.sendRedirect("ypkcxx.html");
	}*/
	/*@RequestMapping("/checkypbm")
	public void checkYPBM(Integer yPBM,HttpServletResponse response) throws IOException{
		Ypkcxx ypxx= ypkcxxService.getYpkcxx(yPBM);
		if(ypxx==null)
			response.getWriter().print("null");
		else
			response.getWriter().print(ypxx.getyPMC());
	}*/
	/*
	@RequestMapping("/findAllYpxx")
	public void findAllYpxx(HttpServletResponse response) throws IOException{
		
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("application/json; charset=utf-8"); 
		JsonObject jsonObject=new JsonObject();
		JSONArray jsonArray=JSONArray.fromObject(ypkcxxService.findAll());
		response.getWriter().print(jsonArray.toString());
	}
	*/
}
